#!/usr/bin/perl -w
use 5.010;

my $names='Fred or Barney';
if($names=~m/(\w+) (and|or) (\w+)/){
	say "I saw $1 and $2";
}

$names='Fred or Barney';
if($names=~m/(?<name1>\w+) (and|or) (?<name2>\w+)/){
	say "I saw $+{name1} and $+{name2}";
}

my $names='Fred Flinstone and Wilma Flinstone';
if($names=~m/(?<last_name>\w+) and \w+ \g{last_name}/){
	say "I saw $+{last_name}";
}

my $names='Fred Flinstone and Wilma Flinstone';
if($names=~m/(?<last_name>\w+) and \w+ \k{last_name}/){
	say "I saw $+{last_name}";
}

if("Hello there,neighbor"=~/\s(\w+),/){
	print "That actually matched '$&'.\n";
}

if("Hello there,neighbor"=~/\s(\w+),/){
	print "That was ($`)($&)($').\n";
	print "Matched: |$`<$&>$'|\n";
}